<?php

require_once 'phpmoko/ui/HasWidgets.php';
require_once 'phpmoko/ui/Widget.php';
require_once 'phpmoko/ui/EmptyWidget.php';

class Panel extends Widget implements HasWidgets, Iterator
{
	private $position = 0;
	protected $spacing = 0;
	private $widgets = array();

	protected function __construct()
	{
		parent::__construct();
	}

	public function setSpacing($spacing)
	{
		$this->spacing = $spacing;
	}

	/**
	 * @param $widget
	 */
	public function add($widget)
	{
		if ($widget instanceof Widget)
			$this->widgets[] = $widget;
		else
			$this->widgets[] = new EmptyWidget($widget);
	}

	/**
	 *
	 */
	public function clear()
	{
		$this->widgets = array();
	}

	/**
	 * @param $widget
	 */
	public function remove($widget)
	{
		foreach ($this->widgets as $key => $value)
			if ($widget == $value)
				unset($this->widgets[$key]);
	}

	/**
	 * @return Widget
	 */
	public function current()
	{
		return $this->widgets[$this->position];
	}

	/**
	 *
	 */
	public function next()
	{
		++$this->position;
	}

	/**
	 *
	 */
	public function key()
	{
		return $this->position;
	}

	/**
	 *
	 */
	public function valid()
	{
		return isset($this->widgets[$this->position]);
	}

	/**
	 *
	 */
	public function rewind()
	{
		$this->position = 0;
	}
}
?>